package cn.assumejson.pro_netty.netty.client.asyn;

import cn.assumejson.pro_netty.netty.client.NettyClient;

import java.util.concurrent.TimeUnit;

/**
 * 子线程，次线程模拟Netty的异步响应结果
 *
 * @author by gang.Li 2022/3/12 11:02
 */
public class SubThread extends Thread {
    private final RequestFuture request;

    public SubThread(RequestFuture request) {
        this.request = request;
    }

    @Override
    public void run() {
        // 模拟额外线程获取响应结果
        Response resp = new Response();
        resp.setId(request.getId());
        resp.setResult("server response" + Thread.currentThread().getId());
        // 子线程模拟
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 返回结果给主线程
        RequestFuture.received(resp);

    }
}
